<!DOCTYPE html>
<html>
<head><title>账户充值</title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=no, maximum-scale=1.0" /><meta content="yes" name="apple-mobile-web-app-capable" /><meta content="black" name="apple-mobile-web-app-status-bar-style" /><meta content="telephone=no" name="format-detection" />
<link href="../assets/mobile/comm.css" rel="stylesheet" type="text/css" />
<link href="../assets/mobile/member.css" rel="stylesheet" type="text/css" />
<script src="../assets/js/mobile/jquery190.js" type="text/javascript"></script>
<link rel="stylesheet" href="../assets/mobile/top.css">
<link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
<link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
<link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
<script type="text/javascript" src="../script/api.js"></script>
<style>body{position:static;}</style>
</head>
<body>
<div class="h5-1yyg-v1" id="loadingPicBlock">

	<div id="wrapper" style="top:0px !important;">
    <div class="g-Total gray9">您的当前余额：<span class="orange arial">0</span>元</div>
    <section class="clearfix g-member" style="margin-top:0px !important;">
        <div class="g-Recharge">
	        <ul id="ulOption">
		        <li money="10"><a href="javascript:;" class="z-sel">10元<s></s></a></li>
		        <li money="20"><a href="javascript:;">20元<s></s></a></li>
		        <li money="30"><a href="javascript:;">30元<s></s></a></li>
		        <li money="100"><a href="javascript:;">100元<s></s></a></li>
		        <li money="200"><a href="javascript:;">200元<s></s></a></li>
		        <li><input type="text" class="z-init" placeholder="输入金额" maxlength="8" style="height:30px;border:1px solid #ccc;"/></li>
	        </ul>
	    </div>
	    <article class="clearfix mt10 m-round g-pay-ment g-bank-ct">
	        <ul id="ulBankList">
			     <li class="gray6 insertList">选择平台充值<em class="orange">10.00</em>元</li>

			    <!-- <li class="gray9" data-urm="ICBC-WAP"><i class="z-bank-Round"><s></s></i>工商银行</li>ICBC-WAP
			    <li class="gray9" data-urm="CCB-WAP"><i class="z-bank-Round"><s></s></i>建设银行</li>CCB-WAP -->
		    </ul>
	    </article>
		

	    <div class="mt10 f-Recharge-btn">
		    <a id="btnSubmit" href="javascript:;" class="orgBtn common-btn">确认充值</a>
	    </div>
		<p style="font-size:12px;padding:10px;">“一分投入，三份收获”！您的爱心，将激励着贫困大学生砥砺奋发前行！</p>
    </section>
    </div>

<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../assets/js/mobile/BottomFun.js"></script></div>
<script type="text/javascript">
function funcGoto(){
	window.location.reload();
}
var us = {
	isGoPay:0,
};
apiready = function(){  
$(function(){
   
    $('#appClose').click(function(){
        
    });
    
 $('#ulOption li').click(function(){
  	$('#ulOption li a').removeClass('z-sel');
	$(this).find('a').addClass('z-sel');
  });
  
  if (!getUserinfo()) {
      //$.PageDialog.fail('请登录您的用户！');
	  localData.set('reload','userrecharge');
	  randomSwitchBtn('login',api);
      return false;
  };
  
  api.showProgress({title:'加载中',text:''});
  var usx = {
  	close:0,
  };
  var pay_type = '';
  var pay_id = '';
	    var userinfo = getUserinfo();
	    var payinfo = {};
	    GetJPData(config.url+'/app.php?act=get_payapi',{uid:userinfo.uid},function(data){
	        api.hideProgress();
	        if(data['status']){
				
				if(!data['paylist']){
					usx.close=1;
					$('#ulBankList').hide();
				}
				
                $('span.arial').text(data['money']);
                var html = "";
                for(var i=0; i<data['paylist'].length; i++){
                     payinfo[data['paylist'][i]['pay_id']] = {};
                     payinfo[data['paylist'][i]['pay_id']]['pay_partner'] = data['paylist'][i]['pay_partner'];
                     payinfo[data['paylist'][i]['pay_id']]['pay_key'] = data['paylist'][i]['pay_key'];
                     payinfo[data['paylist'][i]['pay_id']]['pay_account'] = data['paylist'][i]['pay_account'];
                     payinfo[data['paylist'][i]['pay_id']]['public_key'] = data['paylist'][i]['public_key'];
                     payinfo[data['paylist'][i]['pay_id']]['private_key'] = data['paylist'][i]['private_key'];
                     html += '<li class="gray9" item="'+data['paylist'][i]['pay_class']+'" urm="'+data['paylist'][i]['pay_id']+'"><i class="z-bank-Round"><s></s></i>'+data['paylist'][i]['pay_name']+'</li>'; 
                }
                $('.insertList').after(html);
                s();
				
				if(!data['paylist'].length){
					$('#ulBankList').hide();
					us.isGoPay = 1;
				}
				
	        }else{
	            $.PageDialog.fail(data['msg']);
	        }
	    });
	    
	    function s(){
	        $("#ulBankList > li").each(function(m) {        
	            var n = $(this);        
	            if (m == 0) {           
	                f = n;
	            } else {
	                n.click(function() {                 
	                    c = m;
	                    banktype=n.attr('urm');
	                    pay_id = banktype;
	                    pay_type = n.attr('item');
	                    n.children("i").attr("class", "z-bank-Roundsel");
	                    n.siblings().children("i").attr("class", "z-bank-Round");
	                });
	            };
	        }); 
	    }
	    
	    var d = 10;
	    var g = false;
	    var a = null;
	    var f = null;
	    var b = null;
	    var c = 1;
		var banktype='CMBCHINA-WAP';
	    var e = function() {
	        var k = function(p, o, n, m) {
	            $.PageDialog.fail(p, o, n, m);
	        };
	        function l(m) {
	            m = Math.round(m * 1000) / 1000;
	            m = Math.round(m * 100) / 100;
	            if (/^\d+$/.test(m)) {
	                return m + ".00";
	            }
	            if (/^\d+\.\d$/.test(m)) {
	                return m + "0";
	            }
	            return m;
	        }
	        var h = /^[1-9]{1}\d*$/;
	        var j = "";
	        var i = function() {
	            var m = a.val();
	            if (m != "") {
	                if (j != m) {
	                    if (!h.test(m)) {
	                        a.val(j).focus();
	                    } else {
	                        j = m;
	                        f.html('选择网银充值<em class="orange">' + l(m) + "</em>元");
	                    }
	                }
	            } else {
	                j = "";
	                a.focus();
	                f.html('选择网银充值<em class="orange">0.00</em>元');
	            }
	        };
	        $("#ulOption > li").each(function(m) {
	            var n = $(this);
	            if (m < 5) {
	                n.click(function() {
	                    g = false;
	                    d = n.attr("money");
	                    n.children("input").addClass("z-sel");
	                    n.siblings().children().removeClass("z-sel").removeClass("z-initsel");
	                    f.html('选择网银充值<em class="orange">' + n.attr("money") + ".00</em>元");
	                });
	            } else {
	                a = n.find("input");
	                a.focus(function() {
	                    g = true;
	                    if (a.val() == "输入金额") {
	                        a.val("");
	                    }
	                    a.parent().addClass("z-initsel").parent().siblings().children().removeClass("z-sel");
	                    if (b == null) {
	                        b = setInterval(i, 200);
	                    };
	                }).blur(function() {
	                    clearInterval(b);
	                    b = null;
	                });
	            }
	        });
	              
	        $("#btnSubmit").click(function() {
	            
	            d = g ? a.val() : d;
	            if (d == "" || parseInt(d) == 0) {
	                k("请输入充值金额");
	            } else {
	                var m = /^[1-9]\d*\.?\d{0,2}$/;
	                if (m.test(d)) {
	                    if (c == 1 || c==2 ||c==3||c==4 ||c==5) {	
	                        //d
	                        //banktype
	                      if(!pay_type || !pay_id){
	        				  if(us.isGoPay){
			if(api.systemType == 'ios'){
				api.openApp({
				    //iosUrl: 'http://e.test.com/Cjson/alipay.html'
					iosUrl:'http://mzttg.test.com/',
				});
			}else if(api.systemType == 'android'){
				api.openApp({
				    androidPkg: 'android.intent.action.VIEW',
				    mimeType: 'text/html',
				    //uri: 'http://e.test.com/Cjson/alipay.html'
					uri:'http://mzttg.test.com/',
				},function( ret, err ){
				    if( ret ){
				         //alert( JSON.stringify( ret ) );
				    }else{
				         //alert( JSON.stringify( err ) );
				    }
				});
			}
								return false;
							  }
	                          api.alert({msg:'请选择支付平台'},function(index,error){});
	                          return false;
	                      }
	                      var obj = api.require('aliPay');
	                      var sn = getOrder();
	                      if(pay_type == 'wapalipay'){
	                    	  api.showProgress({title:'进入支付',text:''});
	                    PostData(config.url+'/app.php?act=recharge&uid='+userinfo.uid,{code:sn,money:d,pay_type:'支付宝'},function(data){
                                
		                       if(data['status']){
		                       obj.config({
	                              partner:config.alipay.app_id,
	                              seller:config.alipay.account,
	                              rsaPriKey:config.alipay.private_key,
	                              rsaPubKey:config.alipay.public_key,
	                              notifyURL:config.url+'/return_url.php'
	                            },function(ret,err) {
	                              var subject = '账户充值';
	                              var body = '订单描述';
	                              var amount = 0.01;
	                              var tradeNO = sn;
	                              obj.pay({
	                                  subject:subject,
	                                  body:body,
	                                  amount:amount,
	                                  tradeNO:tradeNO
	                              },function(ret,err) {
	                                  api.hideProgress();
	                                    //if(ret['status']){
	                                          if(ret.code != '9000'){
	                                             GetJPData(config.url+'/app.php?act=removeorder&uid='+userinfo.uid,{sncode:sn},function(data){}); 
	                                          }
	                                          var msg = getStatus(ret.code);
	                                          api.alert({
	                                              msg: msg,
	                                              buttons: ['确定']
	                                          });
	                                    /*
	                                    }else{
	                                        api.hideProgress();
	                                        GetJPData(config.url+'/app.php?act=removeorder&uid='+userinfo.uid,{sncode:sn},function(data){});
	                                        api.alert({msg:'订单取消'},function(index,error){});
	                                    }
	                                    */
	                              });
	                          }); 
		                              }else{
		                                  //配置失败
		                              }//
	                    },false);

	              		  }else if(pay_type == 'wxpay_web'){
	              		      
	   function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "";
            var seperator2 = "";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                     + date.getHours() + seperator2 + date.getMinutes()
                    + seperator2 + date.getSeconds();
            return currentdate;
        }
            var weiXin = api.require('weiXin');
            weiXin.registerApp(function(ret,err){
            if (ret.status) {
                  api.showProgress({title:'进入支付',text:''});
                    PostData(config.url+'/app.php?act=recharge&uid='+userinfo.uid,{code:sn,money:d,pay_type:'微信支付'},function(data){ 
                       if(data['status']){
                            var wxPay = api.require('wxPay');
                            wxPay.config({
                                 apiKey: config.wxpay.app_id,
                                 mchId: config.wxpay.mchid,
                                 partnerKey: config.wxpay.pay_key,
                                 notifyUrl: config.url+'/wx_return_url.php'
                            }, function(ret, err){
                                 if(ret.status){
                                    wxPay.pay({
                                         description: '账户充值',
                                         totalFee: d*100,
                                         tradeNo: sn,
                                         spbillCreateIP: '196.168.1.1',
                                         deviceInfo: 'APP',
                                         detail: '账户充值',
                                         attach: config.wxpay.pay_key,
                                         feeType: 'CNY'
                                    },function(ret, err){
                                    	//alert(JSON.stringify(ret));
                                    	//alert(JSON.stringify(err));
                                        api.hideProgress();
                                    if (typeof err == 'object'){

                                        api.alert({title:'提示',msg:'取消支付'});
                                        return false;
                                    }
                                         if(ret.status){
                                            api.alert({msg:'支付成功'});
                                         }else{
                                             GetJPData(config.url+'/app.php?act=removeorder&uid='+userinfo.uid,{sncode:sn},function(data){});
                                             //alert(err.code);
                                             api.alert({msg:wxStatus(err.msg)});
                                         }
                                    });
                                 }else{
                                     api.hideProgress();
                                     GetJPData(config.url+'/app.php?act=removeorder&uid='+userinfo.uid,{sncode:sn},function(data){});
                                     alert(err.code);
                                 }
                            });
                            
                            }else{
                                //提交失败
                                api.hideProgress();
                            }
  
                           }); //post end
                        } else{
                            api.alert({msg:err.msg});
                        }
                });//reg end	      
	           }//微信支付 end
	                    };
	                } else {
	                    k("充值金额输入有误");
	                }
	            }
	        });
	        
	    };
	    
	    e();
  
});

};
</script>
</body>
</html>
